package mse.eai.jbpm.lotteryResultsProcess;

import java.util.HashMap;
import java.util.Map;

import org.jboss.logging.Logger;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

public class PrepareLotteryWinnerMail implements ActionHandler {

	private static final Logger log = Logger
			.getLogger(PrepareLotteryWinnerMail.class);

	public void execute(ExecutionContext context) throws Exception {

		log.info("Executing ---------->");
		
		try {
			
			log.info("Got from context: " + "amount  = " + context.getVariable("amount"));
			
			String subject ="PhaseBook Lottery Prize Notification";
			String message = "Congratulations ! \n\n" +
			"     You have won the wondrous sum of " + context.getVariable("amount") + " Linden EUROS!  \n\n " +
			"     Keep on betting - every game is a new chance! \n\n\n"+
			"The PhaseBook Lottery team";
			
			context.setVariable("subject", subject);
			context.setVariable("message", message);
			context.setVariable("destUserId", context.getVariable("uid"));
			
			log.info("Set in context: " + "subject  = " + subject);
			log.info("Set in context: " + "message  = " + message);
			log.info("Set in context: " + "destUserId  = " + context.getVariable("uid"));
			
			context.leaveNode();

		} catch (Exception ex) {
			log.error("Exception: ", ex);
			log.error("ProcessInstance will be suspended");
			context.getProcessInstance().suspend();
		}
		
		log.info("<--------------- Done");
	}

}